<?php

declare(strict_types=1);

namespace App\Model;


/**
 * @property int $id ID
 * @property int $userid 用户ID
 * @property int $client 客户端类型 1-Web 2-H5 3-Android 4-iOS
 * @property string $token TOKEN
 * @property int $create_time 创建时间
 * @property int $expire_time 过期时间
 * @property int $update_time 更新时间
 * @property-read null|User $user 
 */
class UserToken extends Model
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'user_token';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'userid', 'client', 'token', 'create_time', 'expire_time', 'update_time'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'userid' => 'integer', 'client' => 'integer', 'create_time' => 'integer', 'expire_time' => 'integer', 'update_time' => 'integer'];

    public function user(){
        return $this->hasOne(User::class, 'id', 'userid')->select(['id', 'username', 'nickname', 'avatar', 'role_id', 'integral']);
    }
}
